<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Shared Worker Example</title>
<script>
if (window.SharedWorker) {
    var sharedWorker = new SharedWorker('shared-worker.js');

    sharedWorker.port.onmessage = function(event) {
        console.log(event.data);
    };
    // sharedWorker.port.postMessage('increment');

    setTimeout(function() {
        document.querySelector('button').onclick = function() {
            sharedWorker.port.postMessage('increment');
        };
    }, 300); // 1000 毫秒 = 1 秒

    
} else {
    console.log('Your browser does not support Shared Workers.');
}
</script>
</head>
<body>
<button>Increase Counter</button>
</body>
</html>